コード例 #1
0
        /// <summary>
        /// Adding or Editing Agent
        /// </summary>
        /// <param name="agentId">For editing agent must be provide an agent Id</param>
        /// <returns></returns>
        public async Task <IActionResult> Add(int?agentId)
        {
            //model dropdowns
            PopulateDropdown();

            var model = new BusinessEntityAddViewModel();

            if (agentId == null)
            {
                return(View(model));
            }

            var agent = await _context.BusinessEntities.FirstOrDefaultAsync(f => f.BusinessId == agentId);

            if (agent == null)
            {
                return(NotFound());
            }
            PopulateDropdown(agent.Status);
            model           = _mapper.Map <BusinessEntityAddViewModel>(agent);
            ViewBag.AgentId = agent.BusinessId;

            return(View(model));
        }
コード例 #2
0
        public async Task <JsonResult> Add(BusinessEntityAddViewModel model, int?agentId)
        {
            if (ModelState.IsValid)
            {
                /*
                 * Flight APIs, Agent Type, Markup Plan is skipped
                 * Because of not matching with Business Entity Data
                 */
                //Edit
                if (agentId != null)
                {
                    var dbAgent = await _context.BusinessEntities.FirstOrDefaultAsync(f => f.BusinessId == agentId);

                    if (dbAgent == null)
                    {
                        return(Json(new { success = false, message = "Can't find this agent" }));
                    }
                    dbAgent = _mapper.Map(model, dbAgent);
                    dbAgent.UpdatedOnUtc = DateTime.UtcNow;

                    try
                    {
                        _context.Update(dbAgent);
                        await _context.SaveChangesAsync();
                    }
                    catch (Exception e)
                    {
                        //log
                        Console.WriteLine(e.Message);
                        return(Json(new { success = false, message = "Can't update the agent" }));
                    }

                    return(Json(new { success = true, message = "Successfully Updated Agent" }));
                }


                var businessEntity = new BusinessEntities
                {
                    State         = model.State,
                    Balance       = model.Balance,
                    City          = model.City,
                    Code          = model.Code,
                    ContactPerson = model.ContactPerson,
                    Country       = model.Country,
                    CreatedOnUtc  = DateTime.UtcNow,
                    Email         = model.Email,
                    Mobile        = model.Mobile,
                    Name          = model.Name,
                    Phone         = model.Phone,
                    ReferredBy    = model.ReferredBy,
                    SMTPPassword  = model.SMTPPassword,
                    SMTPPort      = model.SMTPPort,
                    SMTPServer    = model.SMTPServer,
                    SMTPUsername  = model.SMTPUsername,
                    Status        = model.Status,
                    Street        = model.Street,
                    UpdatedOnUtc  = DateTime.UtcNow,
                    SecurityCode  = model.SecurityCode,
                    Zip           = model.Zip,
                    MarkupPlanId  = model.MarkupPlanId,
                    Logo          = await UploadFile(model.LogoFile, model.Name),
                };
                await _context.BusinessEntities.AddAsync(businessEntity);

                await _context.SaveChangesAsync();

                return(Json(new { success = true, message = "Successfully Added Agent" }));
            }



            return(Json(new { success = false, message = "Something Wrong please check all Inputs" }));
        }