コード例 #1
0
        public static MessageCustom AddServiceOrder(BoardServiceOrder data, int userId, int nodeId)
        {
            MessageCustom msg = new MessageCustom();

            try
            {
                using (var ts = new TransactionScope())
                {
                    #region Entities
                    ServiceOrderBE oServiceOrderBE = new ServiceOrderBE();
                    oServiceOrderBE.v_ServiceOrderId       = data.EntityserviceOrder.v_ServiceOrderId;
                    oServiceOrderBE.v_CustomServiceOrderId = data.EntityserviceOrder.v_CustomServiceOrderId;
                    oServiceOrderBE.v_Description          = data.EntityserviceOrder.v_Description;
                    oServiceOrderBE.v_Comentary            = data.EntityserviceOrder.v_Comentary;
                    oServiceOrderBE.i_NumberOfWorker       = data.EntityserviceOrder.i_NumberOfWorker;
                    oServiceOrderBE.r_TotalCost            = data.EntityserviceOrder.r_TotalCost;
                    oServiceOrderBE.d_DeliveryDate         = data.EntityserviceOrder.d_DeliveryDate;
                    oServiceOrderBE.i_ServiceOrderStatusId = data.EntityserviceOrder.i_ServiceOrderStatusId;
                    oServiceOrderBE.i_LineaCreditoId       = data.EntityserviceOrder.i_LineaCreditoId;
                    oServiceOrderBE.i_MostrarPrecio        = data.EntityserviceOrder.i_MostrarPrecio;
                    oServiceOrderBE.i_EsProtocoloEspecial  = data.EntityserviceOrder.i_EsProtocoloEspecial;


                    List <ServiceOrderDetailBE> ListServiceOrderDetailBE = new List <ServiceOrderDetailBE>();
                    var iter = 0;
                    foreach (var obj in data.ListEntityServiceOrder)
                    {
                        iter++;
                        ProtocolList _prot = new ProtocolList();
                        _prot.v_ProtocolId = obj.v_ProtocolId;

                        bool existName = true;

                        while (existName)
                        {
                            _prot.v_Name = data.EntityserviceOrder.v_OrganizationName + "-" + obj.v_ProtocolTypeName + "-" + iter + "-" + obj.v_GesoName;
                            MessageCustom resultVerify = ProtocolDal.VerifyExistsProtocol(_prot.v_Name);
                            if (resultVerify.Id == null)
                            {
                                existName = false;
                            }
                            else
                            {
                                iter++;
                            }
                        }

                        _prot.v_CustomerOrganizationId   = data.EntityserviceOrder.v_OrganizationId + "|" + data.EntityserviceOrder.v_LocationId;
                        _prot.v_IntermediaryOrganization = data.EntityserviceOrder.v_OrganizationId + "|" + data.EntityserviceOrder.v_LocationId;
                        _prot.v_WorkingOrganizationId    = data.EntityserviceOrder.v_OrganizationId + "|" + data.EntityserviceOrder.v_LocationId;
                        _prot.v_Geso            = obj.v_GroupOccupationId;
                        _prot.i_IsActive        = 1;
                        _prot.i_EsoTypeId       = obj.i_ProtocolType;
                        _prot.i_ServiceTypeId   = 1; //Empresarial
                        _prot.i_MasterServiceId = 2; //Examen de salud ocupacional

                        _prot.ListComponents = obj.ProtocolComponents;

                        var result = ProtocolBL.SaveProtocols(_prot, userId, nodeId);
                        if (result.Error)
                        {
                            throw new Exception(result.Message);
                        }
                        obj.v_ProtocolId = result.Id;

                        ServiceOrderDetailBE oServiceOrderDetailBE = new ServiceOrderDetailBE();
                        oServiceOrderDetailBE.v_ServiceOrderDetailId   = obj.v_ServiceOrderDetailId;
                        oServiceOrderDetailBE.v_ServiceOrderId         = obj.v_ServiceOrderId;
                        oServiceOrderDetailBE.v_ProtocolId             = obj.v_ProtocolId;
                        oServiceOrderDetailBE.r_ProtocolPrice          = obj.r_ProtocolPrice;
                        oServiceOrderDetailBE.i_NumberOfWorkerProtocol = obj.i_NumberOfWorkerProtocol;
                        oServiceOrderDetailBE.r_Total = obj.r_Total;

                        ListServiceOrderDetailBE.Add(oServiceOrderDetailBE);
                    }
                    #endregion

                    string ServiceOrderId = ServiceOrderDal.AddServiceOrder(oServiceOrderBE, ListServiceOrderDetailBE, userId, nodeId);

                    msg.Error   = false;
                    msg.Id      = ServiceOrderId ?? throw new Exception("Sucedió un error al grabar las ordenes, por favor actualice y vuelva a intentar.");
                    msg.Message = "Se guardó correctamente.";
                    msg.Status  = (int)HttpStatusCode.Created;

                    ts.Complete();
                    return(msg);
                }
            }
            catch (Exception ex)
            {
                msg.Message = ex.Message;
                msg.Error   = true;
                msg.Status  = (int)HttpStatusCode.Conflict;
                return(msg);
            }
        }
コード例 #2
0
        public static string AddServiceOrder(ServiceOrderBE pobjDtoEntity, List <ServiceOrderDetailBE> pobjDtoEntityDetail, int userId, int nodeId)
        {
            //mon.IsActive = true;
            string NewId = "(No generado)";

            try
            {
                DatabaseContext dbContext = new DatabaseContext();

                #region Service Order
                if (pobjDtoEntity.v_ServiceOrderId == null) //Add
                {
                    pobjDtoEntity.d_InsertDate   = DateTime.Now;
                    pobjDtoEntity.i_InsertUserId = userId;
                    pobjDtoEntity.i_IsDeleted    = 0;

                    NewId = new Common.Utils().GetPrimaryKey(nodeId, 101, "YY");
                    pobjDtoEntity.v_ServiceOrderId = NewId;

                    dbContext.ServiceOrder.Add(pobjDtoEntity);
                }
                else //update
                {
                    NewId = pobjDtoEntity.v_ServiceOrderId;
                    var objServiceOrder = ctx.ServiceOrder.Where(x => x.v_ServiceOrderId == pobjDtoEntity.v_ServiceOrderId).FirstOrDefault();
                    objServiceOrder.d_UpdateDate           = DateTime.Now;
                    objServiceOrder.i_UpdateUserId         = userId;
                    objServiceOrder.i_MostrarPrecio        = pobjDtoEntity.i_MostrarPrecio;
                    objServiceOrder.i_LineaCreditoId       = pobjDtoEntity.i_LineaCreditoId;
                    objServiceOrder.i_NumberOfWorker       = pobjDtoEntity.i_NumberOfWorker;
                    objServiceOrder.i_ServiceOrderStatusId = pobjDtoEntity.i_ServiceOrderStatusId;
                    objServiceOrder.r_TotalCost            = pobjDtoEntity.r_TotalCost;
                }

                dbContext.SaveChanges();
                #endregion

                #region Service Order Detail

                if (pobjDtoEntityDetail != null)
                {
                    foreach (var item in pobjDtoEntityDetail)
                    {
                        if (item.v_ServiceOrderDetailId == null) //add
                        {
                            item.d_InsertDate   = DateTime.Now;
                            item.i_InsertUserId = userId;
                            item.i_IsDeleted    = 0;
                            // Autogeneramos el Pk de la tabla
                            item.v_ServiceOrderId       = NewId;
                            item.v_ServiceOrderDetailId = new Common.Utils().GetPrimaryKey(nodeId, 102, "YA");

                            dbContext.ServiceOrderDetail.Add(item);
                            dbContext.SaveChanges();
                        }
                        else //Update
                        {
                            var objServiceOrderDetail = dbContext.ServiceOrderDetail.Where(x => x.v_ServiceOrderDetailId == item.v_ServiceOrderDetailId).FirstOrDefault();
                            objServiceOrderDetail.d_UpdateDate             = DateTime.Now;
                            objServiceOrderDetail.i_UpdateUserId           = userId;
                            objServiceOrderDetail.v_ProtocolId             = item.v_ProtocolId;
                            objServiceOrderDetail.r_Total                  = item.r_Total;
                            objServiceOrderDetail.r_ProtocolPrice          = item.r_ProtocolPrice;
                            objServiceOrderDetail.i_NumberOfWorkerProtocol = item.i_NumberOfWorkerProtocol;
                        }
                    }
                    dbContext.SaveChanges();
                }

                #endregion

                return(NewId);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }