示例#1
0
        public ReturnResult SaveGate([FromBody]  GateMaster gateMaster)
        {
            bool   success       = false;
            string message       = "";
            var    currentUserId = HttpContext.Current.User.Identity.GetUserId();

            if (gateMaster.Id == 0)
            {
                var data = _genericService.GateMaster.GetAll().Where(x => x.GateNumber.Trim() == gateMaster.GateNumber.Trim() && x.BuildingId == gateMaster.BuildingId && x.IsActive == true).ToList();
                if (data.Count() == 0)
                {
                    gateMaster.IsActive   = true;
                    gateMaster.CreatedBy  = currentUserId;
                    gateMaster.CreatedOn  = DateTime.UtcNow;
                    gateMaster.UpdatedBy  = currentUserId;
                    gateMaster.UpdatedOn  = DateTime.UtcNow;
                    gateMaster.GateNumber = gateMaster.GateNumber.Trim();
                    _genericService.GateMaster.Insert(gateMaster);
                    message = "Gate saved successfully!!";
                    success = true;
                }
                else
                {
                    return(new ReturnResult {
                        Message = "UnSuccess", Success = false
                    });
                }
            }
            else
            {
                var existinggate = _genericService.GateMaster.GetById(gateMaster.Id);
                if (existinggate != null)
                {
                    var data = _genericService.GateMaster.GetAll().Where(x => x.Id != gateMaster.Id && x.GateNumber.Trim() == gateMaster.GateNumber.Trim() && x.BuildingId == gateMaster.BuildingId && x.IsActive == true).ToList();
                    if (data.Count() == 0)
                    {
                        existinggate.BuildingId = gateMaster.BuildingId;
                        existinggate.GateNumber = gateMaster.GateNumber.Trim();
                        existinggate.UpdatedBy  = currentUserId;
                        existinggate.UpdatedOn  = DateTime.UtcNow;
                        existinggate.CreatedOn  = existinggate.CreatedOn;
                        gateMaster.IsActive     = true;
                        _genericService.GateMaster.Update(existinggate);
                        message = "Gate update successfully!!";
                        success = true;
                    }
                    else
                    {
                        return(new ReturnResult {
                            Message = "UnSuccess", Success = false
                        });
                    }
                }
                ;
            }
            _genericService.Commit();
            return(new ReturnResult {
                Message = message, Success = true
            });
        }
示例#2
0
 public ReturnResult DeleteGate([FromBody] GateMaster GateMaster)
 {
     if (GateMaster != null)
     {
         var GaterDelete = _genericService.GateMaster.GetAll().Where(x => x.Id == GateMaster.Id).FirstOrDefault();
         if (GaterDelete != null)
         {
             if (_genericService.ShitfAssignment.SearchFor(x => x.GateId == GateMaster.Id && x.IsActive == true).Any())
             {
                 return(new ReturnResult {
                     Message = "Please first delete all the shift assigment under this gate", Success = false
                 });
             }
             GaterDelete.IsActive = false;
             _genericService.GateMaster.Delete(GaterDelete);
             _genericService.Commit();
             return(new ReturnResult {
                 Message = "Gate deleted successfully!!", Success = true
             });
         }
     }
     return(new ReturnResult {
         Message = "Failure", Success = false
     });
 }