Exemplo n.º 1
0
        public JsonResult Save(string blockId)
        {
            try
            {
                if (!IsSavePermission(blockId))
                {
                    return(Error("您没有操作权限,请联系系统管理员!"));
                }

                string fTitle   = GetFormValue("fTitle");
                string fTags    = GetFormValue("fTags");
                string fContent = GetFormValue("fContent");

                if (string.IsNullOrWhiteSpace(fTitle))
                {
                    return(Error("区块说明不能为空!"));
                }
                if (string.IsNullOrWhiteSpace(fTags))
                {
                    return(Error("标签不能为空!"));
                }
                if (string.IsNullOrWhiteSpace(fContent))
                {
                    return(Error("内容不能为空!"));
                }

                var entity = new Info_Block()
                {
                    SystemID   = SystemID,
                    CompanyID  = CompanyID,
                    BlockID    = blockId,
                    Title      = fTitle,
                    Tags       = fTags,
                    Content    = fContent,
                    State      = true,
                    CreateDate = DateTime.Now
                };
                bool result = false;
                if (string.IsNullOrEmpty(blockId))
                {
                    result = BlockService.SaveBlock(entity);
                }
                else
                {
                    result = BlockService.UpdateBlock(entity);
                }
                if (result)
                {
                    return(Success("ok"));
                }
                else
                {
                    return(Error("fail"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
        public async Task <ActionResult> CancelBookingAsync(Guid cusId)
        {
            try
            {
                var user   = (await _userManager.GetUserAsync(User)).UserName;
                var ticket = _ticketService.GetTickets(_ => _.CustomerId == cusId.ToString() && _.Block.Date.Date >= DateTime.Now.Date).FirstOrDefault();

                if (ticket == null)
                {
                    return(BadRequest("Hồ sơ này không có lịch để hủy."));
                }
                if (ticket.Block.StartTime <= DateTime.Now.TimeOfDay)
                {
                    return(BadRequest("Đã quá trễ để hủy lịch hôm nay."));
                }

                ticket.BookingDate = null;
                ticket.Note        = null;
                ticket.CustomerId  = null;

                //Thay đổi isFull ở bảng block
                if (ticket.Block.IsFull)
                {
                    ticket.Block.IsFull = false;
                    _blockService.UpdateBlock(ticket.Block, user);
                }
                _ticketService.UpdateTicket(ticket, user);
                _ticketService.Save();
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(Ok());
        }
Exemplo n.º 3
0
 public JsonResult EditBlock(Block block)
 {
     if (!ModelState.IsValid)
     {
         return(Json(new ResultModel(false, block)));
     }
     //Особенность Kendo Editor
     //block.Content = Server.HtmlDecode(block.Content);
     _blockService.UpdateBlock(block);
     return(Json(ResultModel.Success));
 }
 public IActionResult Put(Block value)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState)); // 400
         }
         _blockService.UpdateBlock(value);
         return(Ok(new
         {
             Result = true
         })); //200
     }
     catch (Exception ex)
     {
         return(StatusCode(500, new
         {
             Result = false,
             ErrorMessage = ex.Message
         }));
     }
 }
Exemplo n.º 5
0
        public async Task <ActionResult> ChangeBookingAsync([FromBody] BookingCM model)
        {
            if (CanBook(model.CustomerId))
            {
                return(Ok(false));
            }
            try
            {
                var customer = _customerService.GetCustomer(model.CustomerId);
                if (customer != null)
                {
                    string currentUserName = (await _userManager.GetUserAsync(User)).UserName;

                    //BlockId da duoc check isFull va time lon hon time hien tai
                    var tickets = _ticketService.GetTickets(t => t.BlockId == model.BlockId).ToList();

                    List <Ticket> newTickets = new List <Ticket>();
                    //Check xem Khach hang này đã đặt trong block nay chưa
                    foreach (var item in tickets)
                    {
                        if (item.CustomerId == null)
                        {
                            newTickets.Add(item);
                        }
                        else if (item.CustomerId.Equals(model.CustomerId.ToString()))
                        {
                            return(Ok(false));
                        }
                    }

                    if (newTickets.Count != 0)
                    {
                        //Xoa customer tu Ticket cu va check xem isFull=true thi set isFull = false
                        var currentTicket = _ticketService.GetTickets(t => t.CustomerId == model.CustomerId.ToString() &&
                                                                      t.Block.Date.Date >= DateTime.Now.Date &&
                                                                      t.Status == 0).FirstOrDefault();
                        currentTicket.CustomerId = null;
                        currentTicket.Note       = null;
                        if (currentTicket.Block.IsFull)
                        {
                            currentTicket.Block.IsFull = false;
                        }
                        _ticketService.UpdateTicket(currentTicket, currentUserName);

                        //Gan customer vao ticket va check xem neu con 1 ticket thi set block isFull = true
                        newTickets[0].CustomerId  = model.CustomerId.ToString();
                        newTickets[0].BookingDate = DateTime.Now;
                        newTickets[0].Note        = model.Note;
                        _ticketService.UpdateTicket(newTickets[0], currentUserName);
                        if (newTickets.Count == 1) // Chỉ còn 1 ticket thì update isFull
                        {
                            var block = _blockService.GetBlock(model.BlockId);
                            block.IsFull = true;
                            _blockService.UpdateBlock(block, currentUserName);
                        }
                        _blockService.Save();
                        return(Ok(true));
                    }
                    else
                    {
                        return(Ok(false));
                    }
                }
                else
                {
                    return(BadRequest("Customer does not existed!"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 6
0
 public async Task <Response> UpdateBlock([FromForm] UpdateBlockViewModel model)
 {
     return(await _blockService.UpdateBlock(model));
 }