public bool DeleteSheduling(int id) { if (id <= 0) { return(false); } using (Petz_dbEntities db = new Petz_dbEntities()) { petz_Pet_Scheduling p = db.petz_Pet_Scheduling.FirstOrDefault(x => x.scheduling_id == id); if (p != null) { db.petz_Pet_Scheduling.Remove(p); db.SaveChanges(); return(true); } } return(false); }
public void SetSheduling(SchedulingEntityInsertOrUpdate insertOrUpdate) { if (insertOrUpdate == null) { throw new ArgumentNullException("insertOrUpdate", "InsertOrUpdate is null"); } if (insertOrUpdate.ClientId <= 0) { throw new ArgumentNullException("insertOrUpdate.ClientId", "InsertOrUpdate.ClientId is null"); } if (insertOrUpdate.PetId <= 0) { throw new ArgumentNullException("insertOrUpdate.PetId", "InsertOrUpdate.PetId is null"); } if (insertOrUpdate.CompanyId <= 0) { throw new ArgumentNullException("insertOrUpdate.CompanyId", "InsertOrUpdate.CompanyId is null"); } if (insertOrUpdate.AddressId <= 0) { throw new ArgumentNullException("insertOrUpdate.AddressId", "InsertOrUpdate.AddressId is null"); } if (insertOrUpdate.DateStart > insertOrUpdate.DateEnd) { throw new ArgumentOutOfRangeException("insertOrUpdate.DateStart", "DateStart greater than DateEnd"); } if (insertOrUpdate.DateStart < DateTime.Now.AddMinutes(10)) { throw new ArgumentOutOfRangeException("insertOrUpdate.DateStart", "DateStart greater than today's date"); } using (Petz_dbEntities db = new Petz_dbEntities()) { petz_Pet_Scheduling p; if (insertOrUpdate.Id > 0) { p = db.petz_Pet_Scheduling.FirstOrDefault(x => x.scheduling_id == insertOrUpdate.Id); if (p == null) { p = new petz_Pet_Scheduling(); insertOrUpdate.Id = 0; p.date_insert = DateTime.Now; p.status_id = (int)StatusEnum.EventCreateByClient; //Evento Criado pelo Cliente if (insertOrUpdate.UserId.HasValue) { p.insert_user_id = insertOrUpdate.UserId.Value; } else { p.insert_client_id = insertOrUpdate.ClientId; } } else { p.date_update = DateTime.Now; p.status_id = (int)StatusEnum.EventChangedByClient; //Evento Alterado pelo Cliente if (insertOrUpdate.UserId.HasValue) { p.update_user_id = insertOrUpdate.UserId.Value; } else { p.update_client_id = insertOrUpdate.ClientId; } } } else { p = new petz_Pet_Scheduling { status_id = (int)StatusEnum.EventCreateByClient, date_insert = DateTime.Now }; //Evento Criado pelo Cliente if (insertOrUpdate.UserId.HasValue) { p.insert_user_id = insertOrUpdate.UserId.Value; } else { p.insert_client_id = insertOrUpdate.ClientId; } } int companyAddressId = db.petz_Company_Address.Where(x => x.company_id == insertOrUpdate.CompanyId && x.address_id == insertOrUpdate.AddressId).Select(x => x.company_address_id).FirstOrDefault(); p.client_id = insertOrUpdate.ClientId; p.company_address_id = companyAddressId; p.pet_id = insertOrUpdate.PetId; p.scheduling_comments = insertOrUpdate.Comments; p.scheduling_date_start = insertOrUpdate.DateStart; p.scheduling_date_end = insertOrUpdate.DateEnd; p.service_id = insertOrUpdate.ServiceId; p.employees_id = insertOrUpdate.EmployeeId; if (insertOrUpdate.Id <= 0) { db.petz_Pet_Scheduling.Add(p); } db.SaveChanges(); } }