Beispiel #1
0
        public async Task <IActionResult> PostStatus([FromQuery] long CorporateId, [FromBody] UserCorporateAction action)
        {
            try
            {
                if (action == null || CorporateId == 0 || action.FK_CorporateStatusMasterId == null)
                {
                    return(Ok(new { status = true, Msg = "Server Validation Failed.Bad Request!" }));
                }

                User UserLogin = _CacheManager.GetOrSetUserSession(Request.Query["key"], null);


                CorporateMaster CorpDetails = _context.CorporateMaster
                                              .SingleOrDefault(x => x.Id == CorporateId);

                CorpDetails.UpdateFlag     = false;
                CorpDetails.OstSubmittedOn = DateTime.Now;
                _context.SaveChanges();

                SubmitedCorporate SubCorp = new SubmitedCorporate();
                SubCorp.Balance = CorpDetails.Balance;
                SubCorp.FK_CorporateMasterId   = CorpDetails.Id;
                SubCorp.lstUserCorporateAction = new List <UserCorporateAction>();
                action.UpdatedBy = UserLogin.Id;
                action.UpdatedOn = DateTime.Now;
                SubCorp.lstUserCorporateAction.Add(action);

                _context.Add(SubCorp);
                _context.SaveChanges();
                //_context.CorporateMaster.Add(CorpDetails);



                return(Ok(new { status = true, Msg = "Updated Successfully!" }));
            }
            catch (Exception ex)
            {
                _ErrLogService.Log(ex, HttpContext, JsonConvert.SerializeObject(action));
                return(StatusCode(500, new { Msg = "Internal Server Error", MsgDetail = ex.Message }));
            }
        }
        public async Task <IActionResult> PostStatus([FromQuery] long Id, [FromBody] UserCorporateAction action)
        {
            try
            {
                if (action == null || Id == 0 || action.FK_CorporateStatusMasterId == null)
                {
                    return(Ok(new { status = true, Msg = "Server Validation Failed.Bad Request!" }));
                }

                User UserLogin = _cache.GetOrSetUserSession(Request.Query["key"], null);

                if (action.FK_CorporateStatusMasterId == (int)CorporateStatus.Submition)
                {
                    CorporateMaster CorpDetails = _context.CorporateMaster
                                                  .SingleOrDefault(x => x.Id == Id);

                    if (CorpDetails.UpdateFlag == false)
                    {
                        return(Ok(new { status = false, Msg = "Corporate Already Submited!" }));
                    }

                    CorpDetails.UpdateFlag     = false;
                    CorpDetails.OstSubmittedOn = DateTime.Now;
                    _context.SaveChanges();

                    SubmitedCorporate SubCorp = new SubmitedCorporate();
                    SubCorp.Balance = CorpDetails.Balance;
                    SubCorp.FK_CorporateMasterId   = CorpDetails.Id;
                    SubCorp.lstUserCorporateAction = new List <UserCorporateAction>();
                    action.FK_SubmitedCorporateId  = Id;
                    action.UpdatedBy = UserLogin.Id;
                    action.UpdatedOn = DateTime.Now;
                    SubCorp.lstUserCorporateAction.Add(action);
                    _context.Add(SubCorp);
                    _context.SaveChanges();
                }
                else
                {
                    var corpDetails = _context.SubmitedCorporate.Include(x => x.CorporateMaster)
                                      .Include(x => x.lstUserCorporateAction)
                                      .SingleOrDefault(x => x.Id == action.FK_SubmitedCorporateId);

                    if (corpDetails.lstUserCorporateAction.Count() == 2)
                    {
                        if (corpDetails.lstUserCorporateAction[1].UpdatedBy != UserLogin.Id)
                        {
                            // dont allow other User to change status. once status changed from submited to other status
                            return(Ok(new { status = false, Msg = "Corporate Status Already Changed!" }));
                        }
                    }

                    corpDetails.lstUserCorporateAction.Last().CurrentStatus = false;

                    //corpDetails.lstUserCorporateAction.Where(x => x.FK_SubmitedCorporateId == action.FK_SubmitedCorporateId && x.CurrentStatus == true).ToList().ForEach(x =>
                    //{
                    //    x.CurrentStatus = false;
                    //    // OldUniqueGroupId = x.UniqueGroupId;
                    //});

                    action.UpdatedBy     = UserLogin.Id;
                    action.UpdatedOn     = DateTime.Now;
                    action.CurrentStatus = true;
                    //action.FK_SubmitedCorporateId = Id;
                    corpDetails.lstUserCorporateAction.Add(action);
                    _context.SaveChanges();
                }
                return(Ok(new { status = true, Msg = "Updated Successfully!" }));
            }
            catch (Exception ex)
            {
                _ErrLogService.Log(ex, HttpContext, JsonConvert.SerializeObject(action));
                return(StatusCode(500, new { Msg = "Internal Server Error", MsgDetail = ex.Message }));
            }
        }