예제 #1
0
        public async Task <JsonResult> Save(ReqCreatePromo request)
        {
            if (!string.IsNullOrEmpty(request.OrganisationId))
            {
                var newPromo = new Promo
                {
                    Title            = request.Title,
                    OriginalPrice    = request.OriginalPrice,
                    Price            = request.Price,
                    ShortDescription = request.ShortDescription,
                    ImageText        = request.ImageText,
                    Category         = request.Category,
                    From             = request.From,
                    To                 = request.To,
                    Description        = request.Details,
                    MaxNumberOfVoucher = request.Max,
                    OrganisationId     = ObjectId.Parse(request.OrganisationId)
                };

                ObjectId promoId;

                ObjectId.TryParse(request.Id, out promoId);
                if (promoId != ObjectId.Empty)
                {
                    newPromo.Id = promoId;
                    var existingPromo = await _promoRepository.Get(request.Id);

                    newPromo.Images = existingPromo.Images;
                    await _promoRepository.Update(request.Id, newPromo);
                }
                else
                {
                    newPromo.IsPublished = false;
                    newPromo.Status      = "Draft";
                    await _promoRepository.CreateSync(newPromo);
                }

                return(Json(new JsonGenericResult
                {
                    IsSuccess = true,
                    Result = newPromo.Id.ToString()
                }));
            }

            return(Json(new JsonGenericResult
            {
                IsSuccess = false,
                Message = "Please select an organisation."
            }));
        }