示例#1
0
 /// <summary>
 /// Update Client
 /// </summary>
 /// <returns></returns>
 public Tuple <bool, string> Update()
 {
     try
     {
         using (Easycase.DataModel.EasyCaseDBEntities DB = new DataModel.EasyCaseDBEntities())
         {
             var client = new DataModel.Client
             {
                 FirstName       = this.FirstName,
                 Citizenship     = this.Citizenship,
                 Country         = this.Country,
                 DOB             = this.DOB,
                 Email           = this.Email,
                 ImageId         = this.ImageId,
                 LastName        = this.LastName,
                 MartialStatusId = this.MartialStatusId,
                 Notes           = this.Notes,
                 PhoneNo         = this.PhoneNo,
                 Prefix          = this.Prefix,
                 PurposeId       = this.PurposeId,
                 ID        = this.ID,
                 Deleted   = false,
                 CreatedBy = this.CreatedBy
             };
             DB.Entry(client).State = System.Data.Entity.EntityState.Modified;
             DB.SaveChanges();
         }
         return(new Tuple <bool, string>(true, Messages.SUCCESS));
     }
     catch (Exception ex)
     {
         Logs.SaveLog(ex.Message);
         return(new Tuple <bool, string>(false, ex.Message));
     }
 }
示例#2
0
 public Clients()
 {
     if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
     {
         ClientList    = new ObservableCollection <DataModel.Client>(DataModel.Client.LoadAll());
         CurrentClient = new DataModel.Client();
         SaveAsNew     = true;
         Refresh();
     }
 }
示例#3
0
        public void SaveCurrentClient()
        {
            DataModel.Client matchByCode = ClientList.FirstOrDefault(client => client.IdCode == CurrentClient.IdCode);

            // An IdCode collision occurred and it's not the same client.
            if (matchByCode != null && matchByCode.Id != CurrentClient.Id)
            {
                throw new Exception($"Asiakas tunnisteella {CurrentClient.IdCode} on jo olemassa.");
            }
            if (SaveAsNew && matchByCode == null)
            {
                CurrentClient.Id = null;
            }

            CurrentClient.Save();
            ClientList = new ObservableCollection <DataModel.Client>(DataModel.Client.LoadAll());

            // If the user changes the IdCode and saves the client as new, this updates the Id to the view model.
            CurrentClient = ClientList.First(client => client.IdCode == CurrentClient.IdCode).Copy();
        }
示例#4
0
 /// <summary>
 /// Save data in database
 /// </summary>
 /// <returns></returns>
 public Tuple <bool, string, long> Save()
 {
     try
     {
         long id = 0;
         using (Easycase.DataModel.EasyCaseDBEntities DB = new DataModel.EasyCaseDBEntities())
         {
             var client = new DataModel.Client
             {
                 FirstName       = this.FirstName,
                 Citizenship     = this.Citizenship,
                 Country         = this.Country,
                 DOB             = this.DOB,
                 Email           = this.Email,
                 ImageId         = this.ImageId,
                 LastName        = this.LastName,
                 MartialStatusId = this.MartialStatusId,
                 Notes           = this.Notes,
                 PhoneNo         = this.PhoneNo,
                 Prefix          = this.Prefix,
                 PurposeId       = this.PurposeId,
                 Deleted         = false,
                 CreatedBy       = this.CreatedBy
             };
             DB.Clients.Add(client);
             DB.SaveChanges();
             id = client.ID;
         }
         return(new Tuple <bool, string, long>(true, Messages.SUCCESS, id));
     }
     catch (Exception ex)
     {
         Logs.SaveLog(ex.Message);
         return(new Tuple <bool, string, long>(false, ex.Message, 0));
     }
 }
示例#5
0
 public Client()
 {
     _client = new DataModel.Client();
 }
示例#6
0
 public static bool CanSaveForClient(DataModel.Client client)
 {
     return(DataModel.Client.Exists(client.Id));
 }
示例#7
0
 public static bool CanRemoveClient(DataModel.Client client)
 {
     return(DataModel.Task.LoadAllFor(client).Count() == 0);
 }
示例#8
0
 public void RemoveClient(DataModel.Client client)
 {
     client.Delete();
     ClientList.Remove(client);
 }
示例#9
0
 public void Reset()
 {
     ClientList    = new ObservableCollection <DataModel.Client>(DataModel.Client.LoadAll());
     CurrentClient = new DataModel.Client();
     Refresh();
 }