using MS.DbContexts;
using MS.Entities;
using MS.Entities.SQLite;
using MS.UnitOfWork;
using MS.WebCore.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.Xml.Linq;

namespace MS.Models.ViewModel
{
    public class BuidMembershipGroupViewModel
    {
        [Display(Name = "BUID")]
        [Required(ErrorMessage = "{0}必填")]
        public string CurrentBuId { get; set; }
        [Display(Name = "会员组")]
        [Required(ErrorMessage = "{0}必填")]
        public string MembershipGroupId { get; set; }
        public ExecuteResult CheckField(ExecuteType executeType, IUnitOfWork<SQLiteContext> SQLiteContext)
        {
            ExecuteResult result = new ExecuteResult();
            var repo = SQLiteContext.GetRepository<BuidMembershipGroup>();

            //如果不是新增角色，操作之前都要先检查角色是否存在
            //if (executeType != ExecuteType.Create && !repo.Exists(a => a.Id == Id))
            //{
            //    return result.SetFailMessage("角色不存在");
            //}

            //针对不同的操作，检查逻辑不同
            switch (executeType)
            {
                case ExecuteType.Delete:
              
                case ExecuteType.Update:
                
                case ExecuteType.Create:
                    if (repo.Exists(a => a.CurrentBuId == CurrentBuId && a.MembershipGroupId == MembershipGroupId))
                    {
                        return result.SetFailMessage($"已存在相同的角色名称：{MembershipGroupId}");
                    }
                    break;
                default:
                    break;
            }
            return result;//没有错误，默认返回成功
        }
    }
}
