Exemplo n.º 1
0
        public async Task <IActionResult> PutCorporate([FromRoute] int id, [FromBody] CorporateMaster Corporate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != Corporate.Id)
            {
                return(BadRequest());
            }

            try
            {
                _context.Entry(Corporate).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(StatusCode(200, new { status = true, Msg = "UPDATED" }));
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("Cannot insert duplicate key"))
                {
                    return(Ok(new { status = true, Msg = "Already Exists!" }));
                }
                _ErrLogService.Log(ex, HttpContext);
                return(StatusCode(500, new { status = true, Msg = ex.Message }));
            }
        }
Exemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            CorporateMaster corporateMaster = db.CorporateMasters.Find(id);

            db.CorporateMasters.Remove(corporateMaster);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "Corporate_ID,CorporateShort,CorporateEntityName,C_Country,C_Location,UserUpdate,DateModified,DateAdded")] CorporateMaster corporateMaster)
 {
     if (ModelState.IsValid)
     {
         db.Entry(corporateMaster).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.C_Country = new SelectList(db.CountryLists, "CountryID", "Country", corporateMaster.C_Country);
     return(View(corporateMaster));
 }
Exemplo n.º 4
0
        // GET: CorporateMasters/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CorporateMaster corporateMaster = db.CorporateMasters.Find(id);

            if (corporateMaster == null)
            {
                return(HttpNotFound());
            }
            return(View(corporateMaster));
        }
Exemplo n.º 5
0
        // GET: CorporateMasters/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CorporateMaster corporateMaster = db.CorporateMasters.Find(id);

            if (corporateMaster == null)
            {
                return(HttpNotFound());
            }
            ViewBag.C_Country = new SelectList(db.CountryLists, "CountryID", "Country", corporateMaster.C_Country);
            return(View(corporateMaster));
        }
Exemplo n.º 6
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 ActionResult Create(CorporateMasterViewModel viewmodel)
        //[Bind(Include = "Corporate_ID,CorporateShort,CorporateEntityName,C_Country,C_Location,UserUpdate,DateAdded")] CorporateMaster corporateMaster )
        {
            if (ModelState.IsValid)
            {
                CorporateMaster model = new CorporateMaster();
                model.CorporateEntityName = viewmodel.CorporateEntityName;
                model.CorporateShort      = viewmodel.CorporateShort;
                model.C_Location          = viewmodel.C_Location;
                model.C_Country           = viewmodel.C_Country;
                model.DateAdded           = DateTime.Now;
                model.UserID = User.Identity.GetUserId();

                db.CorporateMasters.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.C_Country = new SelectList(db.CountryLists, "CountryID", "Country", viewmodel.C_Country);
            return(View(viewmodel));
        }
Exemplo n.º 8
0
        public object  SetPriority([FromQuery] int priority, [FromQuery] int CorporateId)
        {
            try
            {
                CorporateMaster Corporate = new CorporateMaster();
                Corporate.Id = CorporateId;

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

                CorpMaster.Priority          = (CorpMaster.Priority == 1) ? 0 : 1;
                CorpMaster.PriorityUpdatedBy = _cache.GetOrSetUserSession(Request.Query["key"], null).Id;
                CorpMaster.PrioriyUpdatedOn  = DateTime.Now;

                _context.SaveChanges();

                return(StatusCode(200, new { status = true, CorpMaster.Priority, Msg = "Priority Set Successfully!" }));
            }
            catch (Exception ex)
            {
                _ErrLogService.Log(ex, HttpContext);
                return(StatusCode(500, new { status = true, Msg = "Internal Server Error", MsgDeatail = ex.Message }));
            }
        }
Exemplo n.º 9
0
        public async Task <IActionResult> PostCorporate([FromBody] CorporateMaster Corporate)
        {
            try
            {
                //string key = Request.Query["key"];
                //User user = _cache.GetOrSetUserSession(key, null);

                //Corporate.CreatedBy =(int)user.Id;

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                bool exists = _context.CorporateMaster.Any(x => x.No_ == Corporate.No_);
                if (!exists)
                {
                    _context.CorporateMaster.Add(Corporate);
                    await _context.SaveChangesAsync();

                    return(Ok(new { status = true, Msg = "Inserted successfully!" }));
                }
                else
                {
                    return(StatusCode(500, new { status = false, Msg = "Corporate Already Exists!" }));
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("Cannot insert duplicate key"))
                {
                    return(StatusCode(500, new { status = true, Msg = "Corporate Already Exists!" }));
                }
                _ErrLogService.Log(ex, HttpContext);
                return(StatusCode(500, new { status = true, Msg = 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 }));
            }
        }