Esempio n. 1
0
        public async Task <int> UpdateProjectMaster(int userID, int companyid, ProjectMasterViewModel projectMasterModel)
        {
            ProjectMaster projectMaster = new ProjectMaster
            {
                Project_ID   = projectMasterModel.ProjectID,
                User_ID      = userID,
                Project_Name = projectMasterModel.ProjectName,
                Address      = projectMasterModel.StreetAddress,
                City         = projectMasterModel.City,
                Status_ID    = projectMasterModel.ProjectStatusID != null?string.Join(",", projectMasterModel.ProjectStatusID) : string.Empty,
                                   Project_Type_ID = projectMasterModel.ProjectTypeID != null?string.Join(",", projectMasterModel.ProjectTypeID) : string.Empty,
                                                         Project_Manager_id = projectMasterModel.ProjectManagerID != null?string.Join(",", projectMasterModel.ProjectManagerID) : string.Empty,
                                                                                  Project_Group_ID = string.Join(",", projectMasterModel.ProjectGroupID),
                                                                                  State            = projectMasterModel.State,
                                                                                  Zip            = projectMasterModel.Zip,
                                                                                  Latitude       = projectMasterModel.Latitude,
                                                                                  Longitude      = projectMasterModel.Longitude,
                                                                                  Internal_Notes = projectMasterModel.InternalNotes,
                                                                                  Lot_Info       = projectMasterModel.LotInfo,
                                                                                  Sub_Notes      = projectMasterModel.SubNotes,
                                                                                  Project_Prefix = projectMasterModel.JobsitePrefix,
                                                                                  Country_ID     = projectMasterModel.CountryID,
                                                                                  Permit_No      = projectMasterModel.Permit,
                                                                                  Org_ID         = companyid,
                                                                                  Contract_Price = projectMasterModel.ContractPrice
            };

            projectMaster = await _projectMasterRepository.UpdateAsync(projectMaster);

            return(projectMaster.Project_ID);
        }
        public async Task <IActionResult> Post([FromBody] ProjectMasterViewModel nProjectCodeMasterVM)
        {
            if (nProjectCodeMasterVM != null)
            {
                var nProjectCodeMaster = this.mapper.Map <ProjectMasterViewModel, ProjectCodeMaster>(nProjectCodeMasterVM);

                // add hour to DateTime to set Asia/Bangkok
                nProjectCodeMaster = helpers.AddHourMethod(nProjectCodeMaster);

                nProjectCodeMaster.CreateDate = DateTime.Now;
                nProjectCodeMaster.Creator    = nProjectCodeMaster.Creator ?? "Someone";

                var insertComplate = await this.repository.AddAsync(nProjectCodeMaster);

                if (insertComplate != null)
                {
                    if (nProjectCodeMasterVM.ProjectSubs != null)
                    {
                        foreach (var nDetail in nProjectCodeMasterVM.ProjectSubs)
                        {
                            nDetail.CreateDate          = nProjectCodeMaster.CreateDate;
                            nDetail.Creator             = nProjectCodeMaster.Creator;
                            nDetail.ProjectCodeMasterId = insertComplate.ProjectCodeMasterId;
                            nDetail.ProjectSubStatus    = ProjectSubStatus.Use;

                            await this.repositorySub.AddAsync(nDetail);
                        }
                    }
                }
                return(new JsonResult(insertComplate, this.DefaultJsonSettings));
            }

            return(NotFound(new { Error = "ProjectMaster not found. " }));
        }
Esempio n. 3
0
 public static void AddProjectMaster(this tbl_project_master project, ProjectMasterViewModel ProjectVm)
 {
     project.id                  = ProjectVm.id;
     project.tenant_id           = ProjectVm.tenant_id;
     project.project_name        = ProjectVm.project_name;
     project.project_description = ProjectVm.project_description;
     project.project_customer    = ProjectVm.project_customer;
 }
 public static void AddProjectMaster(this tbl_project_master projectMaster, ProjectMasterViewModel projectMasterVm)
 {
     projectMaster.tenant_id            = projectMasterVm.tenant_id;
     projectMaster.Project_Code         = projectMasterVm.Project_Code;
     projectMaster.Project_Name         = projectMasterVm.Project_Name;
     projectMaster.Project_Client       = projectMasterVm.Project_Client;
     projectMaster.Project_DeliveryDate = projectMasterVm.Project_DeliveryDate;
     projectMaster.CompID = projectMasterVm.CompID;
     projectMaster.Project_Description = projectMasterVm.Project_Description;
     projectMaster.Project_Equp_Name   = projectMasterVm.Project_Equp_Name;
     projectMaster.Maker_No            = projectMasterVm.Maker_No;
     projectMaster.Created_On          = DateTime.Now;
     projectMaster.Created_By          = projectMasterVm.Created_By;
     projectMaster.Modified_On         = DateTime.Now;
     projectMaster.Modified_By         = projectMasterVm.Modified_By;
 }
 public HttpResponseMessage SaveProjectMaster(HttpRequestMessage request, ProjectMasterViewModel project)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             tbl_project_master newProjectMaster = new tbl_project_master();
             newProjectMaster.AddProjectMaster(project);
             _projectRepository.Add(newProjectMaster);
             _unitOfWork.Commit();
             response = request.CreateResponse <ProjectMasterViewModel>(HttpStatusCode.Created, project);
         }
         return response;
     }));
 }
Esempio n. 6
0
        public void GetProject_ShouldReturnCorrectProject()
        {
            //Arrange
            var _project = new ProjectMasterViewModel()
            {
                ProjectID = 1, ProjectCode = "A001", ProjectName = "ABC Bearings Ltd", IsActive = true, IsDeleted = false, Status = "Active"
            };

            _IProjectRepository.Expect(s => s.GetById(1))
            .IgnoreArguments()
            .Return(_project);
            ProjectController controller = new ProjectController(_IProjectRepository, _logger);
            //Act
            var result        = controller.GetById(2);
            var contentResult = result as OkNegotiatedContentResult <ProjectMasterViewModel>;
            var expected      = (contentResult.Content) as ProjectMasterViewModel;

            //Assert
            Assert.IsNotNull(result);
            var projects = GetMockProjects();

            Assert.AreEqual(projects.ToList()[0].ProjectName, expected.ProjectName);
        }
Esempio n. 7
0
        public void SaveProjectTest()
        {
            var _projectRepositoryMock = new Mock <IEntityBaseRepository <tbl_project_master> >();
            var _errorsRepositoryMock  = new Mock <IEntityBaseRepository <tbl_error> >();
            var _unitOfWorkMock        = new Mock <IUnitOfWork>();
            var mockMapper             = new Mock <IMapper>();

            //var list = new List<tbl_project_master>
            //    {
            //        new tbl_project_master{id=1,tenant_id=1,project_name="SmartCity"},
            //        new tbl_project_master{id=2,tenant_id=1,project_name="Sales"},
            //        new tbl_project_master{id=3,tenant_id=1,project_name="Ecommerce"},
            //    };

            //_projectRepositoryMock.Setup(x => x.GetSingle(1)).Returns(new tbl_project_master { id = 1, tenant_id = 1, project_name = "SmartCity" });

            var controller = new ProjectMasterController(_projectRepositoryMock.Object, _errorsRepositoryMock.Object, _unitOfWorkMock.Object);
            var config     = new HttpConfiguration();

            controller.Configuration = config;
            var Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:34351/api/ProjectMaster/SaveProjectMaster");

            Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;

            var newProject = new ProjectMasterViewModel()
            {
                project_name = "Inventory Mgmt"
            };

            var response = controller.SaveProjectMaster(Request, newProject);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            var newSavedProject = JsonConvert.DeserializeObject <tbl_project_master>(response.Content.ReadAsStringAsync().Result);

            Assert.AreEqual("Inventory Mgmt", newSavedProject.project_name);
            //Assert.AreEqual(newProject.project_name, _projectRepository.GetAll().OrderByDescending(x=>x.id).First().project_name);
        }
        public async Task <IActionResult> PutByNumber(int key, [FromBody] ProjectMasterViewModel uProjectCodeMasterVm)
        {
            var Message = "Job can't update";

            try
            {
                if (uProjectCodeMasterVm != null)
                {
                    var uProjectCodeMaster = this.mapper.Map <ProjectMasterViewModel, ProjectCodeMaster>(uProjectCodeMasterVm);

                    // add hour to DateTime to set Asia/Bangkok
                    uProjectCodeMaster = helpers.AddHourMethod(uProjectCodeMaster);
                    // set modified
                    uProjectCodeMaster.ModifyDate = DateTime.Now;
                    uProjectCodeMaster.Modifyer   = uProjectCodeMaster.Modifyer ?? "Someone";

                    // update Master not update Detail it need to update Detail directly
                    var updateComplate = await this.repository.UpdateAsync(uProjectCodeMaster, key);

                    if (updateComplate != null)
                    {
                        // filter
                        Expression <Func <ProjectCodeSub, bool> > condition = m => m.ProjectCodeMasterId == key;
                        var dbProjectSubs = this.repositorySub.FindAll(condition);

                        //Remove ProjectCodeDetails if edit remove it
                        foreach (var dbDetail in dbProjectSubs)
                        {
                            try
                            {
                                if (!uProjectCodeMasterVm.ProjectSubs.Any(x => x.ProjectCodeSubId == dbDetail.ProjectCodeSubId))
                                {
                                    dbDetail.ProjectSubStatus = ProjectSubStatus.NotUse;
                                    await this.repositorySub.UpdateAsync(dbDetail, dbDetail.ProjectCodeSubId);
                                }
                            }
                            catch (Exception ex)
                            {
                                Message = ex.ToString();
                            }
                        }
                        //Update ProjectCodeDetails
                        foreach (var uProjectSub in uProjectCodeMasterVm.ProjectSubs)
                        {
                            // Set Value
                            uProjectSub.ProjectSubStatus = uProjectSub.ProjectSubStatus ?? ProjectSubStatus.Use;

                            if (uProjectSub.ProjectCodeSubId > 0)
                            {
                                uProjectSub.ModifyDate = uProjectCodeMaster.ModifyDate;
                                uProjectSub.Modifyer   = uProjectCodeMaster.Modifyer;

                                await this.repositorySub.UpdateAsync(uProjectSub, uProjectSub.ProjectCodeSubId);
                            }
                            else
                            {
                                if (uProjectSub.ProjectCodeMasterId < 1 || uProjectSub.ProjectCodeMasterId == null)
                                {
                                    uProjectSub.ProjectCodeMasterId = updateComplate.ProjectCodeMasterId;
                                }

                                uProjectSub.CreateDate = uProjectCodeMaster.ModifyDate;
                                uProjectSub.Creator    = uProjectCodeMaster.Modifyer;

                                await this.repositorySub.AddAsync(uProjectSub);
                            }
                        }
                    }

                    return(new JsonResult(updateComplate, this.DefaultJsonSettings));
                }
            }
            catch (Exception ex)
            {
                Message = $"Has error {ex.ToString()}";
            }
            return(NotFound(new { Error = Message }));
        }