Beispiel #1
0
        private async Task <bool> InsertHosoFromFile(HosoCourier hoso, IHosoCourrierRepository _rpCourrier)
        {
            var id = await _rpCourrier.Create(hoso);

            if (!string.IsNullOrWhiteSpace(hoso.LastNote))
            {
                var note = new GhichuModel
                {
                    Noidung = hoso.LastNote,
                    HosoId  = id,
                    UserId  = GlobalData.User.IDUser,
                    TypeId  = (int)NoteType.HosoCourrier
                };
                await _rpNote.AddNoteAsync(note);
            }
            if (hoso.AssigneeIds == null || !hoso.AssigneeIds.Any())
            {
                hoso.AssigneeIds = new List <int>();
            }
            hoso.AssigneeIds.Add(GlobalData.User.IDUser);
            hoso.AssigneeIds.Add(1);//Thainm
            var tasks = new List <Task>();

            foreach (var assingeeId in hoso.AssigneeIds)
            {
                tasks.Add(_rpCourrier.InsertCourierAssignee(id, assingeeId));
            }
            await Task.WhenAll(tasks);

            return(true);
        }
Beispiel #2
0
        public async Task <ActionResult> Create(HosoCorrierRequestModel model)
        {
            if (model == null)
            {
                return(ToResponse(false, "Dữ liệu không hợp lệ", 0));
            }
            if (model.AssignId <= 0)
            {
                return(ToResponse(false, "Vui lòng chọn Courier", 0));
            }
            var sale = await _rpEmployee.GetEmployeeByCode(model.SaleCode.ToString().Trim());

            if (sale == null)
            {
                return(ToResponse(false, "Sale không tồn tại, vui lòng kiểm tra lại"));
            }
            var hoso = new HosoCourier
            {
                CustomerName = model.CustomerName,
                Cmnd         = model.Cmnd,
                Status       = (int)HosoCourierStatus.New,
                LastNote     = model.LastNote,
                CreatedBy    = GlobalData.User.IDUser,
                SaleCode     = model.SaleCode,
                Phone        = model.Phone,
                AssignId     = model.AssignId,
                GroupId      = model.GroupId,
                DistrictId   = model.DistrictId,
                ProvinceId   = model.ProvinceId
            };

            var id = await _rpCourierProfile.Create(hoso);

            if (id > 0)
            {
                var tasks = new List <Task>();
                var ids   = new List <int>()
                {
                    model.AssignId, GlobalData.User.IDUser, 1
                };                                                                      //1 is Thainm
                if (!string.IsNullOrWhiteSpace(model.SaleCode))
                {
                    if (sale != null)
                    {
                        ids.Add(sale.Id);
                    }
                }
                foreach (var assigneeId in ids)
                {
                    tasks.Add(_rpCourierProfile.InsertCourierAssignee(id, assigneeId));
                }
                await Task.WhenAll(tasks);

                if (!string.IsNullOrWhiteSpace(model.LastNote))
                {
                    var note = new GhichuModel
                    {
                        Noidung = model.LastNote,
                        HosoId  = id,
                        UserId  = hoso.CreatedBy,
                        TypeId  = (int)NoteType.HosoCourrier
                    };
                    await _rpNote.AddNoteAsync(note);
                }

                return(ToResponse(true, "", id));
            }
            return(ToResponse(false));
        }