Example #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);
        }
Example #2
0
        public async Task <bool> Update(int id, HosoCourier hoso)
        {
            using (var con = GetConnection())
            {
                var param = GetParams(hoso, ignoreKey: new string[] {
                    nameof(hoso.CreatedTime),
                    nameof(hoso.UpdatedTime),
                    nameof(hoso.AssigneeIds),
                    nameof(hoso.CreatedBy)
                });

                await con.ExecuteAsync("sp_UpdateHosoCourier", param, commandType : CommandType.StoredProcedure);

                return(true);
            }
        }
Example #3
0
        public async Task <int> Create(HosoCourier hoso, int groupId = 0)
        {
            try
            {
                using (var con = GetConnection())
                {
                    var param = GetParams(hoso, "Id", DbType.Int32, ignoreKey: new string[] {
                        nameof(hoso.CreatedTime),
                        nameof(hoso.UpdatedTime),
                        nameof(hoso.UpdatedBy),
                        nameof(hoso.AssigneeIds)
                    });
                    await con.ExecuteAsync("sp_InsertHosoCourrier", param, commandType : CommandType.StoredProcedure);

                    return(param.Get <int>("Id"));
                }
            }
            catch (Exception e)
            {
                return(0);
            }
        }
Example #4
0
        public async Task <ActionResult> Update(HosoCorrierRequestModel model)
        {
            if (model == null || model.Id <= 0)
            {
                return(ToResponse(false, "Dữ liệu không hợp lệ"));
            }
            if (string.IsNullOrWhiteSpace(model.CustomerName))
            {
                return(ToResponse(false, "Tên khách hàng không được để trống"));
            }
            if (model.AssignId <= 0)
            {
                return(ToResponse(false, "Vui lòng chọn courier"));
            }
            var profile = await _rpCourierProfile.GetById(model.Id);

            if (profile == null)
            {
                return(ToJsonResponse(false, "Hồ sơ không tồn tại"));
            }
            bool isAdmin = await _rpEmployee.CheckIsAdmin(GlobalData.User.IDUser);

            if (profile.Status == (int)TrangThaiHoSo.Cancel)
            {
                if (!isAdmin)
                {
                    return(ToJsonResponse(false, "Bạn không có quyền, vui lòng liên hệ Admin"));
                }
            }
            var sale = null as OptionSimple;


            var hoso = new HosoCourier
            {
                CustomerName = model.CustomerName,
                Cmnd         = model.Cmnd,
                Status       = model.Status,
                LastNote     = model.LastNote,
                UpdatedBy    = GlobalData.User.IDUser,
                Phone        = model.Phone,
                SaleCode     = model.SaleCode,
                AssignId     = model.AssignId,
                Id           = model.Id,
                GroupId      = model.GroupId,
                DistrictId   = model.DistrictId,
                ProvinceId   = model.ProvinceId
            };

            var result = await _rpCourierProfile.Update(model.Id, hoso);

            if (result)
            {
                if (!string.IsNullOrWhiteSpace(model.SaleCode))
                {
                    if (sale != null)
                    {
                        await _rpCourierProfile.InsertCourierAssignee(model.Id, sale.Id);
                    }
                }
                _rpCourierProfile.InsertCourierAssignee(model.Id, model.AssignId);
                if (!string.IsNullOrWhiteSpace(model.LastNote))
                {
                    var note = new GhichuModel
                    {
                        Noidung = model.LastNote,
                        HosoId  = model.Id,
                        UserId  = hoso.UpdatedBy,
                        TypeId  = (int)NoteType.HosoCourrier
                    };
                    await _rpNote.AddNoteAsync(note);
                }
            }
            return(ToResponse(true));
        }
Example #5
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));
        }
Example #6
0
        public async Task <List <HosoCourier> > ReadXlsxFile(MemoryStream stream, int createBy)
        {
            var importExelFrameWork = await _rpTailieu.GetImportTypes((int)HosoType.HosoCourrier);

            BusinessExtentions.GetObjectParams(importExelFrameWork);
            //return null;
            var result   = new TupleModel();
            var workBook = WorkbookFactory.Create(stream);
            var sheet    = workBook.GetSheetAt(0);
            var rows     = sheet.GetRowEnumerator();
            var hasData  = rows.MoveNext();
            var param    = new DynamicParameters();
            var pars     = new List <DynamicParameters>();
            int count    = 0;
            var hosos    = new List <HosoCourier>();

            for (int i = 1; i < sheet.PhysicalNumberOfRows; i++)
            {
                try
                {
                    var row = sheet.GetRow(i);
                    if (row != null)
                    {
                        if (row.Cells.Count > 1)
                        {
                            bool isNullRow = row.Cells.Count < 3 ? true : false;
                        }

                        foreach (var col in importExelFrameWork)
                        {
                            param.Add(col.Name, BusinessExtentions.TryGetValueFromCell(row.Cells[col.Position].ToString(), col.ValueType));
                        }
                        pars.Add(param);
                        var hoso = new HosoCourier()
                        {
                            CustomerName = row.Cells[0] != null ? row.Cells[0].ToString() : "",
                            Phone        = row.Cells[1] != null ? row.Cells[1].ToString() : "",
                            Cmnd         = row.Cells[2] != null ? row.Cells[2].ToString() : "",
                            LastNote     = row.Cells[4] != null ? row.Cells[4].ToString() : "",
                            ProvinceId   = row.Cells[5] != null?Convert.ToInt32(row.Cells[5].ToString()) : 0,
                                               DistrictId = row.Cells[6] != null?Convert.ToInt32(row.Cells[6].ToString()) : 0,
                                                                SaleCode  = row.Cells[7] != null ? row.Cells[7].ToString().Trim().ToLower() :string.Empty,
                                                                Status    = (int)HosoCourierStatus.New,
                                                                CreatedBy = createBy
                        };
                        var strAssignee    = row.Cells[3] != null ? row.Cells[3].ToString() : "";
                        var assigneeIdsStr = string.IsNullOrWhiteSpace(strAssignee) ? new List <string>() : strAssignee.Split(',').ToList();
                        var assigneeIds    = (assigneeIdsStr != null && assigneeIdsStr.Any()) ? assigneeIdsStr.Select(s => Convert.ToInt32(s)).ToList() : new List <int>();
                        hoso.AssigneeIds = assigneeIds;
                        hoso.AssignId    = assigneeIds.FirstOrDefault();

                        hoso.GroupId = await _rpCourierProfile.GetGroupIdByNguoiQuanLyId(hoso.AssignId);

                        hosos.Add(hoso);
                        count++;
                    }
                }
                catch
                {
                    return(hosos);
                }
            }
            return(hosos);
        }