Esempio n. 1
0
 public bool SaveDepartmentRoles(DepartmentRoles role)
 {
     try
     {
         var existingUserCount = this.DepartmentRoles.Count(a => a.BranchID.Equals(role.BranchID) && a.DepartmentID.Equals(role.DepartmentID));
         if (existingUserCount == 0)
         {
             // insert user
             role.Active = true;
             DepartmentRoles.Add(role);
         }
         else
         {
             DepartmentRoles u = this.DepartmentRoles.Where(a => a.BranchID.Equals(role.BranchID) && a.DepartmentID.Equals(role.DepartmentID)).FirstOrDefault <DepartmentRoles>();
             // change contact in disconnected mode (out of DBContext scope)
             if (u != null)
             {
                 u.BranchID     = role.BranchID;
                 u.DepartmentID = role.DepartmentID;
                 u.FunctionHead = role.FunctionHead;
                 u.SVP          = role.SVP;
                 u.Active       = true;
             }
             this.Entry(u).State = EntityState.Modified;
         }
         this.SaveChanges();
         return(true);
     }
     catch
     {
         throw;
     }
 }
 public HttpResponseMessage Post(DepartmentRoles role)
 {
     try
     {
         bool res = this._repo.SaveDepartmentRoles(role);
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, res);
         return(response);
     }
     catch (Exception ex)
     {
         _tracer.Error(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex.StackTrace);
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content = new StringContent(ex.Message)
         });
     }
 }
Esempio n. 3
0
 public bool SaveDepartmentRoles(DepartmentRoles role)
 {
     return(this.DataContext.SaveDepartmentRoles(role));
 }