public BranchOfficeModel GetByID(int Id) { BranchOfficeModel branchOffice = new BranchOfficeModel(); try { var _branchOffice = fcontext.BranchOffice.First(a => a.Id == Id); // fBranchOfficeFactoryAsync.GetById(Id); branchOffice.Id = _branchOffice.Id; branchOffice.Code = _branchOffice.Code; branchOffice.Name = _branchOffice.Name; branchOffice.Adress = _branchOffice.Address; branchOffice.Observation = _branchOffice.Observation; branchOffice.Active = _branchOffice.Active; branchOffice.StarHour = _branchOffice.StarHour; branchOffice.EndHour = _branchOffice.EndHour; branchOffice.DateCreated = _branchOffice.DateCreated; branchOffice.DateUpdated = _branchOffice.DateUpdated; branchOffice.StringStartHour = branchOffice.StarHour?.ToString().Remove(branchOffice.StarHour.ToString().Length - 3) ?? string.Empty; branchOffice.StringEndHour = branchOffice.EndHour?.ToString().Remove(branchOffice.EndHour.ToString().Length - 3) ?? string.Empty; } catch (Exception ex) { branchOffice = null; } return(branchOffice); }
public int Add(BranchOfficeModel aModel) { int result = 0; //await Task.Run(() => //{ try { BranchOffice aNew = new BranchOffice { Code = aModel.Code, Name = aModel.Name, Address = aModel.Adress, Observation = aModel.Observation, Active = true, StarHour = aModel.StarHour, EndHour = aModel.EndHour, DateCreated = DateTime.Now }; fcontext.BranchOffice.Add(aNew); fcontext.SaveChanges(); //fBranchOfficeFactoryAsync.Save(aNew); //fGymUnitOfWork.Commit(); result = aNew.Id; } catch (Exception ex) { result = 0; } //}); return(result); }
public bool Update(BranchOfficeModel aModel) { bool result = false; //await Task.Run(() => //{ try { var getToUpdate = fcontext.BranchOffice.First(a => a.Id == aModel.Id); //fBranchOfficeFactoryAsync.GetById(aModel.Id); getToUpdate.Code = aModel.Code; getToUpdate.Name = aModel.Name; getToUpdate.Address = aModel.Adress; getToUpdate.Observation = aModel.Observation; getToUpdate.Active = aModel.Active; getToUpdate.StarHour = aModel.StarHour; getToUpdate.EndHour = aModel.EndHour; getToUpdate.DateUpdated = aModel.DateUpdated; fcontext.Entry(getToUpdate).State = System.Data.Entity.EntityState.Modified; fcontext.SaveChanges(); return(true); //fBranchOfficeFactoryAsync.Update(getToUpdate); //fGymUnitOfWork.Commit(); //result = true; } catch (Exception ex) { result = false; } //}); return(result); }
private void ButtonAgregarEliminar_Click(object sender, RoutedEventArgs e) { BranchOfficeModel branchOffice = DataGridBranchOffice.SelectedItem as BranchOfficeModel; if (branchOffice != null) { GRDialogConsultation _var = new GRDialogConsultation(); _var.Message = "Eliminar Registro Selecionado?"; if (_var.ShowDialog() == true) { int id = branchOffice.Id; var result = branchOfficeServices.DeleteUpdate(id); if (result) { MyCollection.Remove(branchOffice); DataGridBranchOffice.ItemsSource = MyCollection; DataGridBranchOffice.Items.Refresh(); lblTotalReg.Content = "Cantidad de Registro: " + MyCollection.Count; } } } else { GRDialogInformation _var = new GRDialogInformation(); _var.Message = "Debe Seleccionar un Registro"; _var.ShowDialog(); } }
public IActionResult GetInventory(long branchOfficeId = 0, long warehouseId = 0, long productId = 0) { try { List <object> result = new List <object>(); var data = _baseRepo.GetAll <Inventory>(x => x.Include(i => i.Product) .Include(i => i.Warehouse) .Include(i => i.BranchOffice) .Include(i => i.Unit) , y => y.Active == true && (branchOfficeId > 0 ? y.BranchOfficeId == branchOfficeId : y.BranchOfficeId > 0) && (warehouseId > 0 ? y.WarehouseId == warehouseId : y.WarehouseId > 0) && (productId > 0 ? y.ProductId == productId : y.ProductId > 0)) .GroupBy(x => x.BranchOfficeId) .ToList(); data.ForEach(i => { BranchOfficeModel branchOffice = new BranchOfficeModel() { Id = i.FirstOrDefault().BranchOffice.Id, Name = i.FirstOrDefault().BranchOffice.Name }; List <WarehouseModel> warehouses = new List <WarehouseModel>(); i.GroupBy(x => x.WarehouseId).ToList().ForEach(w => { warehouses.Add(new WarehouseModel() { Id = w.FirstOrDefault().Warehouse.Id, Name = w.FirstOrDefault().Warehouse.Name }); }); warehouses.ForEach(n => { n.Inventory = i.Where(e => e.WarehouseId == n.Id).Select(x => new InventoryModel() { ProductId = x.ProductId, Product = new BaseModel { Id = x.Product.Id, Name = x.Product.Name }, Unit = new BaseModel() { Id = x.Unit.Id, Name = x.Unit.Name }, UnitId = x.UnitId, Quantity = x.Quantity, }).ToList(); }); branchOffice.Warehouses = warehouses; result.Add(branchOffice); }); return(Ok(new { id = 0, status = 0, message = "ok_msg", data = result })); } catch (Exception ex) { return(Ok(new { id = -1, status = -1, message = "error_msg" })); } }
private void CmbBranchOffice_SelectionChanged(object sender, SelectionChangedEventArgs e) { int val = int.Parse(CmbBranchOffice.SelectedValue.ToString()); if (val > 0) { BranchOfficeModel branchOffice = _branchOfficeServices.GetByID(val); HourStart = branchOffice.StarHour; HourEnd = branchOffice.EndHour; } }
private void Button_Modificar(object sender, RoutedEventArgs e) { BranchOfficeModel branchOfficeModelModel = DataGridBranchOffice.SelectedItem as BranchOfficeModel; if (branchOfficeModelModel != null) { int?id = branchOfficeModelModel.Id; this.Close(); var _window = new BranchOfficeImput(id); _window.Show(); } else { GRDialogInformation _var = new GRDialogInformation(); _var.Message = "Debe Seleccionar un Registro"; _var.ShowDialog(); } }
public bool DeleteUpdate(int Id) { bool result = false; BranchOfficeModel aModel = new BranchOfficeModel(); try { BranchOffice branchOffice = fcontext.BranchOffice.Find(Id); fcontext.BranchOffice.Remove(branchOffice); fcontext.SaveChanges(); result = true; } catch (Exception ex) { aModel = GetByID(Id); aModel.Active = false; result = Update(aModel); //Update Change Estatus Active } return(result); }
private void Button_Aplicar(object sender, RoutedEventArgs e) { bool hourStart = Common.ValidateHour(mkbHoraInicio.Text); bool hourEnd = Common.ValidateHour(mkbHoraFin.Text); if (!string.IsNullOrEmpty(TxtSucursal.Text.Trim()) || !string.IsNullOrEmpty(TxtCodigo.Text.Trim())) { if ((hourStart) && (hourEnd)) { if (TimeSpan.Parse(mkbHoraInicio.Text) < TimeSpan.Parse(mkbHoraFin.Text)) { int result = 0; BranchOfficeModel _class = new BranchOfficeModel(); _class.Code = TxtCodigo.Text.Trim(); _class.Name = TxtSucursal.Text.Trim(); _class.Adress = TxtDir.Text.Trim(); _class.Observation = TxtObs.Text.Trim(); _class.StarHour = TimeSpan.Parse(mkbHoraInicio.Text); _class.EndHour = TimeSpan.Parse(mkbHoraFin.Text); _class.Active = CmbActive.Text == "Activo"; var existBranchOffice = branchOfficeServices.GetByCode(TxtCodigo.Text.Trim()); if (LblId.Content == "0") //ADD { if (existBranchOffice == null) { result = branchOfficeServices.Add(_class); LblId.Content = result.ToString(); } else { GRDialogInformation _error0 = new GRDialogInformation(); _error0.Message = "El Codigo ingresado ya esta en uso"; _error0.ShowDialog(); TxtCodigo.Focus(); } } else //EDIT { int _id = int.Parse(LblId.Content.ToString()); if ((existBranchOffice == null) || (existBranchOffice.Id == _id)) { _class.Id = _id; var task = branchOfficeServices.Update(_class); result = task ? _id : 0; } } if (result > 0) { GRDialogConsultation _var = new GRDialogConsultation(); _var.Message = "Registro Guardado, desea crear otro Registro?"; if (_var.ShowDialog() == true) { CleanControls(); TxtSucursal.Focus(); } else { var window = new BranchOfficeList(); this.Close(); window.ShowDialog(); } } else { GRDialogError _error = new GRDialogError(); _error.Message = "Ocurrion un error al guardar el resgitro"; _error.ShowDialog(); } } else { GRDialogInformation _error1 = new GRDialogInformation(); _error1.Message = "La Hora de Inicio no puede ser mayor a la Hora Fin"; _error1.ShowDialog(); } } else { GRDialogInformation _error2 = new GRDialogInformation(); _error2.Message = "Verificar campos Obligatorios / Formato de Horas"; _error2.ShowDialog(); } } else { GRDialogInformation _error2 = new GRDialogInformation(); _error2.Message = "Verificar campos Obligatorios"; _error2.ShowDialog(); } }