public int AddComponent(ComponentListDTO component) { try { // insert compoent if (component.ComponentId == 0) { decimal maxId = context.ComponentLists.Select(mm => mm.ComponentId).DefaultIfEmpty(0).Max(); component.ComponentId = ++maxId; ComponentList target = new ComponentList(); component.Mapper(target); context.ComponentLists.Add(target); } else { // update component ComponentList exCmpList = context.ComponentLists.Where(ll => ll.ComponentId == component.ComponentId).FirstOrDefault(); exCmpList.ComponentName = component.ComponentName; exCmpList.UpdatedBy = component.UpdatedBy; exCmpList.UpdatedDate = component.UpdatedDate; exCmpList.IsActive = component.IsActive; exCmpList.IsDeleted = component.IsDeleted; } int cnt = context.SaveChanges(); return(cnt); } catch (Exception exc) { return(0); } }
private void CreateObjet(string IsDelete) { compDto = new ComponentListDTO(); if (IsDelete == "Y") { compDto.IsDeleted = "Y"; } else { compDto.IsDeleted = "N"; } if (hfIsUpdate.Value == "N") { compDto.ComponentId = 0; compDto.InsertedBy = Session["USERID"].ToString(); compDto.InsertedDate = DateTime.Now; } else { compDto.ComponentId = Convert.ToDecimal(hfID.Value.ToString()); compDto.UpdatedBy = Session["USERID"].ToString(); compDto.UpdatedDate = DateTime.Now; } compDto.ComponentName = txtCompName.Text.Trim(); compDto.IsActive = chkInActive.Checked ? "N" : "Y"; }